var http = require("http");
var url = require("url");
var DynamicTool = require("./Tools/DynamicTool");
var DynamicDao = require("./DAO/DynamicDao");

var server = http.createServer(function(req, res){
	
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader("Access-Control-Allow-Headers", "X-Requested-With"); 
    res.setHeader("Content-type", "text/html;charset=utf-8");
    var param = url.parse(req.url, true);
    var strQuery = param.pathname;
    if (strQuery == "/searchAllDynamic") {
    	
    	DynamicTool.postData(req, function(param){
    		
    		DynamicDao.searchAllDynamic(param,function(err, rows){
    			var rtn = [];
    			if(err || rows.length==0){
                    rtn={
                        state:"err"
                    }
                    var sJson=JSON.stringify(rtn);
                    
                }else{
                	var sJson=JSON.stringify(rows);
                }
    			console.dir("aaaaaa");
    			console.log(rows)
    			console.dir(sJson);
    			res.end(sJson);
    		});
    	});
    	
    }else if(strQuery=="/path2"){
	
    }else if(strQuery=="/path3"){
    	
    }else{

    }
	

});

server.listen(3000);
console.log("已启动")